//
//  Driver.m
//  DriverBus
//
//  Created by MacMini20170218 on 2017/3/27.
//  Copyright © 2017年 JiYang. All rights reserved.
//

#import "Driver.h"

@implementation Driver

//重写的toString方法
- (NSString*)description{
    return [NSString stringWithFormat:@"%@,%@,%@,%@,%@,%@",self.name,self.number,
            self.sex,self.account,self.pass,self.imageUrl];
}

- (void)saveToData:(Boolean)hasLog{
    //保存已经登录和用户信息
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setBool:hasLog forKey:DRIVER_LOG];
    [defaults setValue:self.name forKey:DRIVER_NAME];
    [defaults setObject:self.number forKey:DRIVER_NUMBER];
    [defaults setObject:self.sex forKey:DRIVER_SEX];
    [defaults setObject:self.account forKey:DRIVER_ACCOUNT];
    [defaults setObject:self.pass forKey:DRIVER_PASS];
    [defaults setObject:self.imageUrl forKey:DRIVER_IMAGE];
}

//获取
- (id)initWithData{
    self = [super init];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    self.name = [defaults objectForKey:DRIVER_NAME];
    self.sex = [defaults objectForKey:DRIVER_SEX];
    self.number = [defaults objectForKey:DRIVER_NUMBER];
    self.account = [defaults objectForKey:DRIVER_ACCOUNT];
    self.pass = [defaults objectForKey:DRIVER_PASS];
    self.imageUrl = [defaults objectForKey:DRIVER_IMAGE];
    return self;
}

@end
